package ch.gibb.learnit.client.controllers;

import ch.gibb.learnit.client.util.soap.Word;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * Controller for statistics
 *
 * @author Bernard Jaquet
 * @version 1.0
 */
public class StatisticAction extends MasterAction {
    //OUT
    private int level1;
    private int level2;
    private int level3;
    private int level4;
    private int level5;

    //Class
    private final Logger masterLogger = Logger.getLogger(StatisticAction.class);

    @Override
    public int openPage() {
        // Setting title of page
        super.title = "Statistiken";

        // Checks if user is logged in
        if (!loginCheck())
            return 403;

        // Generates the values for the Statistics
        try {
            List<Word> words = client.getAllWords(getUser());
            if (words == null) {
                getErrors().addMessage("Statistiken konnten wegen eines internen Fehlerns nicht geladen werden");
                return 0;
            }
            for (Word word : words) {
                switch (word.getLevel()) {
                    case 1:
                        level1++;
                        break;
                    case 2:
                        level2++;
                        break;
                    case 3:
                        level3++;
                        break;
                    case 4:
                        level4++;
                        break;
                    case 5:
                        level5++;
                        break;
                    default:
                        break;
                }
            }
        } catch (Exception e) {
            getErrors().addMessage("Statistiken konnten wegen eines internen Fehlerns nicht geladen werden");
            masterLogger.error("Could not load statistics because " + e.getMessage(), e);
        }

        return 0;
    }

    public int getLevel1() {
        return level1;
    }

    public void setLevel1(int level1) {
        this.level1 = level1;
    }

    public int getLevel2() {
        return level2;
    }

    public void setLevel2(int level2) {
        this.level2 = level2;
    }

    public int getLevel3() {
        return level3;
    }

    public void setLevel3(int level3) {
        this.level3 = level3;
    }

    public int getLevel4() {
        return level4;
    }

    public void setLevel4(int level4) {
        this.level4 = level4;
    }

    public int getLevel5() {
        return level5;
    }

    public void setLevel5(int level5) {
        this.level5 = level5;
    }
}
